package com.gxa.p2p.service.impl;

import com.gxa.p2p.mapper.ActivityMapper;
import com.gxa.p2p.pojo.Activity;
import com.gxa.p2p.pojo.Activitylog;
import com.gxa.p2p.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author R
 * @data 2021-10-27 10:06
 */
@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    ActivityMapper mapper = null;

    @Override
    public List<Activity> findNewActivityByPage(Integer page, Integer size) {
        List<Activity> newActivityByPage = mapper.findNewActivityByPage((page - 1) * size, size);
        return newActivityByPage;
    }

    @Override
    public Integer findNewActivityCount(Integer page, Integer size) {
        page = null;
        size = null;
        List<Activity> newActivityByPage = mapper.findNewActivityByPage(page,size);
        return newActivityByPage.size();
    }

    @Override
    public void updateNewActivity(Activity activity) {
        mapper.updateNewActivity(activity);
    }

    @Override
    public List<Activity> findSignActivityByPage(Integer page, Integer size) {
        List<Activity> signActivityByPage = mapper.findSignActivityByPage((page - 1) * size, size);

        return signActivityByPage;
    }

    @Override
    public Integer findSignActivityCount(Integer page, Integer size) {
        page = null;
        size = null;
        List<Activity> signActivityByPage = mapper.findSignActivityByPage(page, size);
        return signActivityByPage.size();
    }

    @Override
    public void updateSignActivity(Activity activity) {
        mapper.updateSignActivity(activity);
    }

    @Override
    public List<Activity> findInviteActivityByPage(Integer page, Integer size) {
        List<Activity> inviteActivityByPage = mapper.findInviteActivityByPage((page - 1) * size, size);
        return inviteActivityByPage;
    }

    @Override
    public Integer findInviteActivityCount(Integer page, Integer size) {
        page = null;
        size = null;
        List<Activity> inviteActivityByPage = mapper.findInviteActivityByPage(page, size);
        return inviteActivityByPage.size();
    }

    @Override
    public void updateInviteActivity(Activity activity) {
        mapper.updateInviteActivity(activity);
    }

    @Override
    public List<Activitylog> findActivityLogByPage(String phone, String name, String event, Boolean state, String from, String to, Integer page, Integer size) {
        if (page == null){
            List<Activitylog> activityLogByPage = mapper.findActivityLogByPage(phone, name, event, state, from, to, page, size);
            return activityLogByPage;
        }else {
            List<Activitylog> activityLogByPage = mapper.findActivityLogByPage(phone, name, event, state, from, to, (page - 1) * size, size);
            return activityLogByPage;
        }

    }

    @Override
    public Integer findActivityLogCount(String phone, String name, String event, Boolean state, String from, String to, Integer page, Integer size) {
        page = null;
        size = null;
        List<Activitylog> activityLogByPage = mapper.findActivityLogByPage(phone, name, event, state, from, to, page, size);
        return activityLogByPage.size();
    }
}
